//
//  GlNode.m
//  ChipmunkEditor
//
//  Created by Rewolf Us on 11-2-26.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "GlNode.h"
#import "chipmunk.h"


@implementation GlNode
@synthesize radius;

-(void)draw{
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_TEXTURE_2D);
	
	glPointSize(3);
	glLineWidth(1);
	glColor4ub(255, 255, 0, 255);
	glPushMatrix();
	glTranslatef(-20, -20, 0);
	static const GLfloat circleVAR[] = {
		0.0000,  1.0000,
		0.2588,  0.9659,
		0.5000,  0.8660,
		0.7071,  0.7071,
		0.8660,  0.5000,
		0.9659,  0.2588,
		1.0000,  0.0000,
		0.9659, -0.2588,
		0.8660, -0.5000,
		0.7071, -0.7071,
		0.5000, -0.8660,
		0.2588, -0.9659,
		0.0000, -1.0000,
		-0.2588, -0.9659,
		-0.5000, -0.8660,
		-0.7071, -0.7071,
		-0.8660, -0.5000,
		-0.9659, -0.2588,
		-1.0000, -0.0000,
		-0.9659,  0.2588,
		-0.8660,  0.5000,
		-0.7071,  0.7071,
		-0.5000,  0.8660,
		-0.2588,  0.9659,
		0.0000,  1.0000,
		0.0f, 0.45f, // For an extra line to see the rotation.
	};
	static const int circleVAR_count = sizeof(circleVAR)/sizeof(GLfloat)/2;
	
	//cpBody *body = _shape->body;
	int extraPtOffset =0;
	
	glVertexPointer(2, GL_FLOAT, 0, circleVAR);
	
	//ccDrawCircle(cpvzero, circle->r, 0, 30, _drawDecoration);
	
	glPushMatrix(); {
		//cpVect center = cpvsub(anchorPoint_, cpv(0.5f, 0.5f));
		//glTranslatef(-center.x*contentSize_.width, -center.y*contentSize_.height, 0.0f);
		
		glScalef(radius*CC_CONTENT_SCALE_FACTOR(), radius*CC_CONTENT_SCALE_FACTOR(), 1.0f);
		
		/*if (_fillShape)
		 glDrawArrays(GL_TRIANGLE_FAN, 0, circleVAR_count-extraPtOffset-1);
		 else*/
		glDrawArrays(GL_LINE_STRIP, 0, circleVAR_count-extraPtOffset);
	} glPopMatrix();
	
	glPopMatrix();
	
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glEnable(GL_TEXTURE_2D);
	
}

@end
